import { ref, reactive, computed } from 'vue'
import { defineStore } from 'pinia'
import { getStorage, setStorage, removeStorage } from '@/utils/storage';

export const useMenusStore = defineStore('menus', () => {
  const menusList = getStorage('menus') ?? ''
  const menus = ref(menusList)
  const btnsPremissan = ref(getStorage('btnsPremissan') ?? '')

  const setMenus = (allMenus, role) => {
    let menusPremission = allMenus.filter(val => val.premisson.includes(role))
    
    menus.value = menusPremission
    setStorage('menus', menusPremission)
  }

  const setBtnsPremissan = (allPremisson, role) => {
    console.log(allPremisson, role);
    
    let premission = allPremisson[role]
    
    btnsPremissan.value = premission
    setStorage('btnsPremissan', premission)
  }

  const clearMenus = data => {
    menus.value = ''
    removeStorage('menus')
  }

  return { menus, setMenus, clearMenus, btnsPremissan, setBtnsPremissan}
})
